package com.zhijian.medical.util;

/**
 * @author HCG
 * @version 1.0
 * @date 2022/5/12
 */
public class NumUtil {

    public static Integer[] range(int start, int stop, int step) {
        if (start < stop) {
            step = Math.abs(step);
        } else {
            if (start <= stop) {
                return new Integer[]{start};
            }

            step = -Math.abs(step);
        }

        int size = Math.abs((stop - start) / step) + 1;
        Integer[] values = new Integer[size];
        int index = 0;
        int i = start;

        while (true) {
            if (step > 0) {
                if (i > stop) {
                    break;
                }
            } else if (i < stop) {
                break;
            }

            values[index] = i;
            ++index;
            i += step;
        }

        return values;
    }
}
